//
//  XWMainViewController.swift
//  XWSinaWeibo
//
//  Created by 徐小伟 on 16/7/20.
//  Copyright © 2016年 Xuxiaowei. All rights reserved.
//

import UIKit

class XWMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar=XWMainTabBar()
        
//        使用 KVC 赋值
        setValue(mainTabbar, forKey: "tabBar")
        
        addChildViewControllers()

    }

    private func addChildViewControllers(){
    
//        let home=XWHomeViewController()
//        
////        设置 tabbarItemTitile
//        home.tabBarItem.title="首页"
//        home.tabBarItem.image=UIImage(named: "tabbar_home")
//        addChildViewController(home)
        
        addChildViewController(XWHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(XWMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(XWDiscoveryViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(XWProfileViewController(), title: "我 ", imageName: "tabbar_profile")
    }
    
    
//    添加子视图的属性的方法
    private func addChildViewController(vc:UIViewController,title:String,imageName:String){
//        vc.tabBarItem.title=title
//        vc.navigationItem.title=title
        vc.title=title
        vc.tabBarItem.image=UIImage(named: imageName)
//        设置图片的颜色
        vc.tabBarItem.selectedImage=UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        设置字体的颜色
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        tabBar.tintColor=UIColor.orangeColor()
        
//        添加导航视图控制器
        let nav=UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
   

}
